<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>


<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>



<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
<title>场外证券业务报告系统</title>
	
</head>
<body >
	<style>
		.debt{
			color:#4689cd !important;
		}
	</style>
	<div id="tb" class="easyui-layout" style="background: #f4f8fc;">
		
			<!-- 【2】曾经受托人 不可以操作数据 -->
			<c:if test="${authType!=2}">
				<a href="javascript:void(0)" style="display:none;" onclick="shwoDurationRecord('','',2)" class="easyui-linkbutton" id="addBtn" iconCls="icon-add"		plain="true">新增</a>
			</c:if>
			
		
		<!-- 【2】曾经受托人 不可以操作数据 -->
		<c:if test="${authType!=2}">
			<a href="javascript:void(0)" style="display:none;" onclick="doDelete()" class="easyui-linkbutton" id="delBtn" iconCls="icon-remove" plain="true">删除</a>
		</c:if>
		
			<a href="javascript:void(0)" onclick="initTable()" class="easyui-linkbutton" id="searchBtn" iconCls="icon-search" plain="true">查询</a>
			<a href="javascript:void(0)" onclick="clearItemValue()" class="easyui-linkbutton" iconCls="icon-reset" plain="true">重置</a>
	
		
		
		<!--<a href="javascript:void(0)" onclick="initTable()" class="easyui-linkbutton" iconCls="icon-search" plain="true">查询</a>-->
		
		<div style="height: 0;clear: both;overflow:hidden;"></div>
		<hr style="height: 1px;margin-top: 0;border:0;background:#dde0d7;"/>
		债券名称:
		<input class="easyui-textbox" type="text" id="searchBondName" />
		报告状态:
		<select class="easyui-combobox" id="searchState" style="width:100px;">
			<option value="">--</option>
			<option value="1">草稿</option>
			<option value="2">已提交</option>
			<option value="3">审核中</option>
			<option value="4">处理中</option>
			<option value="26">无效</option>
		</select>
		<div style="height:10px;width:100%;background:#e4eaf5;margin-top:4px;margin-bottom: 0;padding-bottom: 0" ></div>
	</div>
	<table id="tt"  class="easyui-datagrid" singleSelect="true" ></table>
	
	<input type="hidden" id="authType" value="${authType}" />
	
		<input type="hidden" id="isCheckUser" value="true" />

	
		<input type="hidden" id="isOperUser" value="true" />


<script type="text/javascript">
	var selectReportId = null;
	var isCheckUser = null;
	var isOperUser = null;
	var basePath = "";
	// 页面加载
	$(document).ready(function (){
		isCheckUser = $('#isCheckUser').val();
		isOperUser = $('#isOperUser').val();
		// 填报用户显示添加删除按钮
		if(isOperUser == 'true'){
			$('#addBtn').show();
			$('#delBtn').show();
		}
		initTable();
	});
	
	// 初始化定期报告列表
	function initTable(){
		// 查询参数
		var queryParams = {};
		//queryParams.orgName = $('#searchOrgName').val();
		queryParams.qspp_BondsName = $('#searchBondName').val();
		queryParams.state = $('#searchState').combobox('getValue');
		queryParams.pid = '${pid}';
		
		$("#tt").datagrid({
			url : basePath+'durationRecord/query.do',
			iconCls : 'icon-save',
			width : '90%',
			pagination : true,
			pageSize : 20,
			pageList : [ 10, 20, 30 ],
			fit : true,
			fitColumns : false,
			resizeHandle:'right',
			singleSelect:true, 
			autoRowHeight:true, 
			striped:true, 
			collapsible:true, 
			/* nowrap : false,  */
			border : false, 
			idField : 'id',
			toolbar:"#tb",
			loadMsg:'',
			rownumbers:true,
			queryParams:queryParams,
			sortName:'create_time',
			sortOrder:'desc',
			columns : [[
				{title : '债券名称',field : 'qspp_BondsName',width : '180px',align:'center',halign:'center'},
				{title : '债券代码',field : 'qspp_ProductCode',width : '70px',align:'center',halign:'center'},
				{title : '发行方式',field : 'qspp_MethodOfIssuing',width : '100px',align:'center',halign:'center',
					formatter:function(value,field,index){
						if(value == '1'){
							return '单独发债';
						} else if(value == '2'){
							return '集合发债';
						}
						return '--';
					}
				},
				{title : '发行人数量',field : 'qspp_NumberOfIssuers',width : '100px',align:'center',halign:'center'},
				{title : '状态',field : 'state',width : '70px',align:'center',halign:'center',
					formatter:function(value,field,index){
						if(value == '1'){
							return '草稿';
						}else if(value == '2'){
							return '已提交';
						}else if(value == '3'){
							return '审核中';
						}else if(value == '4'){
							return '处理中';
						}else if(value == '5'){
							return '退回补正';
						}else if(value == '6'){
							return '拒绝补正';
						}else if(value == '7'){
							return '通过';
						}else if(value == '8'){
							return '驳回';
						}else if(value == '26'){
							return '无效';
						}
						return '';
					}
				},
				{title : '提交时间',field : 'recentSubmitTime',width : '150px',align:'center',halign:'center'
					/* ,
					formatter:function(value,field,index){
						return formatDate(value,'yyyy-MM-dd hh:mm:ss');
					} */
				},
				{title : '操作',field : 'taskassignee',width : '220px',align:'center',halign:'center',
					formatter:function(value,field,index){
						var e = '';
						<shiro:hasPermission name="CCIB:SEARCH">
							e += '<a target="_blank" class="debt" onclick="shwoDurationRecord(\''+field.id+'\', \''+field.M_ID+'\',1, \''+field.state+'\')">查看</a> ';
						</shiro:hasPermission>
						
						// 审核角色
						if(isCheckUser == 'true'){
							if(field.state == '2'){// 状态：待审核(提交)
								//e += '<a target="_blank" class="debt" onclick="shwoDurationRecord(\''+field.id+'\', \''+field.M_ID+'\',4)">审核</a> ';
								<shiro:hasPermission name="CCIB:EXAMINE">
									e += '<a target="_blank" class="debt" onclick="shwoDurationRecord(\''+field.id+'\', \''+field.M_ID+'\', 5, \''+field.state+'\')">审核</a> ';
								</shiro:hasPermission>
							}else if(field.state == '3'){// 状态：申请变更 --> 可删除
								<shiro:hasPermission name="CCIB:EXAMINE">
									e += '<a target="_blank" class="debt" onclick="delete4CheckUser(\''+field.groupId+'\', \''+field.id+'\', \''+field.M_ID+'\')">废除</a> ';
								</shiro:hasPermission>
								
								<shiro:hasPermission name="CCIB:EXAMINE">
									e += '<a target="_blank" class="debt" onclick="showApplyCorrect(\''+field.id+'\', \''+field.M_ID+'\', \''+field.groupId+'\', \''+field.state+'\')">回复申请</a> ';
								</shiro:hasPermission>
								
							}
							<shiro:hasPermission name="CCIB:EXAMINE">
								e += '<a target="_blank" class="debt" onclick="showHistory(\''+field.groupId+'\', \''+field.id+'\')">历史管理</a> ';
							</shiro:hasPermission>
							
							return e;
						}
						
						// 填报用户显示操作按钮 
						if(isOperUser == 'true' ){
							if(field.state == '1'){// 状态：草稿
								//【2】曾经受托人 不可以操作数据 
								if('${authType}'!='2'){
									<shiro:hasPermission name="CCIB:ADD">
										e += '<a target="_blank" class="debt" onclick="shwoDurationRecord(\''+field.id+'\', \''+field.M_ID+'\', 3, 1)">编辑</a> ';
									</shiro:hasPermission>
								}
							}else if(field.state == '2'){// 状态：待审核(提交)
								<shiro:hasPermission name="CCIB:ADD">
									e += '<a target="_blank" class="debt" onclick="showApplyCorrect(\''+field.id+'\', \''+field.M_ID+'\', \''+field.groupId+'\', \''+field.state+'\')">申请变更</a> ';
								</shiro:hasPermission>
							}else if(field.state == '3'){// 状态：申请变更
								<shiro:hasPermission name="CCIB:ADD">
									e += '<a target="_blank" class="debt" onclick="showApplyCorrect(\''+field.id+'\', \''+field.M_ID+'\', \''+field.groupId+'\', \''+field.state+'\')">申请变更</a> ';
								</shiro:hasPermission>
							}else if(field.state == '4'){// 状态：获准补正
									<shiro:hasPermission name="CCIB:ADD">
										e += '<a target="_blank" class="debt" onclick="shwoDurationRecord(\''+field.id+'\', \''+field.M_ID+'\', 3, 4)">补正</a> ';
									</shiro:hasPermission>
								//e += '<a target="_blank" class="debt" onclick="showApplyCorrect(\''+field.id+'\', \''+field.M_ID+'\', \''+field.groupId+'\', \''+field.state+'\')">申请确认</a> ';
							}else if(field.state == '5'){// 状态：退回补正
								<shiro:hasPermission name="CCIB:ADD">
									e += '<a target="_blank" class="debt" onclick="shwoDurationRecord(\''+field.id+'\', \''+field.M_ID+'\',3, 5)">变更</a> ';
								</shiro:hasPermission>
								
							}else if(field.state == '6'){// 状态：拒绝补正
								<shiro:hasPermission name="CCIB:ADD">
									e += '<a target="_blank" class="debt" onclick="showApplyCorrect(\''+field.id+'\', \''+field.M_ID+'\', \''+field.groupId+'\', \''+field.state+'\')">申请确认</a> ';
								</shiro:hasPermission>
								
							}else if(field.state == '7'){// 状态：通过
								//e += '<a target="_blank" class="debt" onclick="showApplyCorrect(\''+field.id+'\', \''+field.M_ID+'\')">补正申请</a> ';
								e += '<a target="_blank" class="debt" onclick="shwoDurationRecord(\''+field.id+'\', \''+field.M_ID+'\',3)">维护</a> ';
							}else if(field.state == '8'){// 状态：驳回
							}
						}
						return e;
					}
				}
			]],
			onLoadSuccess:function(data){
				$(this).datagrid('doCellTip', { 'max-width': '400px', 'delay': 500 });
			}
		});	
	}
	
	//清空查询条件
	function clearItemValue(){
		$("#searchBondName").textbox("setValue","");
		$('#searchState').combobox('select','');   
	}
	
	function delete4CheckUser(id, groupId, mid){
		$.messager.confirm('操作提醒', '</br>是否确认操作当前记录?</br></br>',
				function(r) {
					if (r) {
						var param = {};
						param.id = "groupId-" + id;
						param.groupId = groupId;
						param.bizId = mid;
						$.ajax({
							type : 'post',
							url : basePath+'durationRecord/delete.do',
							data : param,  
							dataType : 'json',
							traditional : true,
							success : function(data) {
								if (data.code == 1) {
									showTimeoutMsg('操作成功！',250,null);
									reloadTable();
								}else{
									showTimeoutMsg('操作失败，请联系系统管理员或稍后再试！',250,null);
								}
							},
							error : function(xmlHttpRequest, error) { // 设置表单提交出错
								showTimeoutMsg('操作失败，请联系系统管理员或稍后再试！',250,null);
							},
						});
					}
				});
	}
	
	// 删除操作
	function doDelete() {
		var data = $("#tt").datagrid('getSelected');
		if (data == null) {
			showTimeoutMsg('请选择需要删除的记录',250,null);
			return;
		}
		if(data.state != '1'){
			showTimeoutMsg('已提交的数据不允许删除',250,null);
			return;
		}
		$.messager.confirm('删除提醒', '</br>确定删除这条信息吗?</br></br>',
			function(r) {
				if (r) {
					var param = {};
					param.id = data.groupId;
					param.groupId = data.id;
					$.ajax({
						type : "post",
						url : basePath+'durationRecord/delete.do',
						data : param,  
						dataType : 'json',
						success : function(data) {
							if (data.code == 1) {
								showTimeoutMsg('删除成功！',250,null);
								$("#tt").datagrid('unselectAll');
								reloadTable();
							}else{
								//showTimeoutMsg(data.msg||'删除失败',250,null);
								$.messager.alert("操作提示", data.message.replace("系统异常：", "") || '操作失败，请联系系统管理员或稍后再试！');
							}
						},
						error : function(xmlHttpRequest, error) { // 设置表单提交出错
							showTimeoutMsg('操作失败，请联系系统管理员或稍后再试！',250,null);
						},
					});
				}
			}
		);
	}
	
	// 打开新页签
	function shwoDurationRecord(id,mid,state, submit_state) {
		var title = getThisTabTitle();
		var url = basePath+'durationRecord/showUpdate?pid=${pid}&id='+id+'&mid='+mid+'&state=' + submit_state;
		
		if(state==1){// 打开查看窗口
			title += '-查看';
			url += '&isUpdate=false';
		}else if(state==2){// 打开新增窗口
			title += "-新增";
			url += '&isUpdate=true';
		}else if(state==3){// 打开编辑窗口
			title += "-修改";
			url += '&isUpdate=true';
		}else if(state==4){// 打开审核窗口
			title += "-审核";
			url += '&isUpdate=true';
		}else if(state==5){// 打开审核窗口
			title += "-审核";
			url += '&isUpdate=false&sh=y';
		}
		
		showNewTab(title,url);
	}
	
	// 打开申请补正页面
	function showApplyCorrect(id, mid,groupId, state) {
		var url=basePath+"durationRecord/showApplyCorrect?id="+id + "&groupId=" + groupId +"&mid="+mid+ "&state=" + state;
		var title = '申请变更-'+getThisTabTitle();
		if (parent.$('#tabs').tabs('exists', title)){
			parent.$('#tabs').tabs('select', title);
			var currentTab = parent.$('#tabs').tabs('getSelected');
			parent.$('#tabs').tabs('update', {
				tab: currentTab,
				options: {
					content: '<iframe scrolling="auto" frameborder="0"  src="'+url+'" style="width:100%;height:100%;"></iframe>'
				}
			})
		} else {
			var content = '<iframe scrolling="auto" frameborder="0"  src="'+url+'" style="width:100%;height:100%;"></iframe>';
			parent.$('#tabs').tabs('add',{
				title:title,
				content:content,
				closable:true
			});
		}
	}
	
	// 打开历史管理列表页面
	function showHistory(groupId, id) {
		var url=basePath+"durationRecord/showHistoryList?groupId="+groupId + "&id=" + id;
		var title = getThisTabTitle()+'-历史管理';
		showNewTab(title,url);
	}
	
	// 显示新增、修改页签
	function showNewTab(title,url){
		if (parent.$('#tabs').tabs('exists', title)){
			parent.$('#tabs').tabs('select', title);
			reload(url);
		} else {
			var content = '<iframe scrolling="auto" frameborder="0"  src="'+url+'" style="width:100%;height:100%;"></iframe>';
			parent.$('#tabs').tabs('add',{
				title:title,
				content:content,
				closable:true
			});
		}
	}
	
	// 刷新表格
	function reloadTable(){
		$("#tt").datagrid('reload');
	}
	
</script>
</body>
</html>
